package com.zhongjianjian.leguansuo.redislister;

import com.alibaba.fastjson.JSON;
import com.zhongjianjian.leguansuo.service.TestLgService;
import com.zhongjianjian.redisLock.entity.TestStock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.connection.MessageListener;
import org.springframework.stereotype.Component;

/**
 * 作者: LCG
 * 日期: 2020/2/22 00:32
 * 描述:
 */
@Component
public class MyLgRedisListener implements MessageListener {

    @Autowired
    private TestLgService testLgService;

    @Override
    public void onMessage(Message message, byte[] bytes) {
        System.out.println("====redis======");
        String channel=new String(message.getChannel());//获取通道
        if(channel.equals("LG")){
            String json=new String(message.getBody());
            TestStock testStock = JSON.parseObject(json, TestStock.class);
            testLgService.testStock(testStock);
        }
    }
}
